//
//  SleepTemperatureViewModel.swift
//  DaRings
//
//  Created by 尹琼 on 2022/12/20.
//

import UIKit
import RxSwift
import RxCocoa

open class SleepTemperatureViewModel: NSObject {
    
    public let providerRelay: BehaviorRelay<SleepProvider?>
    
    public let dateRelay: BehaviorRelay<Date?>
    
    public let sevenTemperatureDiffs: BehaviorRelay<SleepTemperatureModel?>
    
    
   public init(providerRelay: BehaviorRelay<SleepProvider?>) {
        
       self.providerRelay = providerRelay
       dateRelay = BehaviorRelay<Date?>(value: nil)
       sevenTemperatureDiffs = BehaviorRelay<SleepTemperatureModel?>(value: nil)
       
       super.init()
       
       providerRelay.map { provider ->Date? in
           
           guard let provider = provider else {
               return nil
           }
           
           return provider.date
           
       }.bind(to: dateRelay).disposed(by: rx.disposeBag)
       
       
       
       providerRelay.map { provider ->SleepTemperatureModel? in
           
           guard let provider = provider else {
               return nil
           }
           return provider.sevenDaysTemperatureDiff
           
       }.bind(to: sevenTemperatureDiffs).disposed(by: rx.disposeBag)
       
       

    }

}
